<?php
//	if(isset($_POST['login'])) {
//                $userid = $_POST['p3dbuserid'];
//                $userpsw = md5($_POST['p3dbuserpsw']);
//                setcookie("p3dbuserid",$userid,time()+(60*60*24*365));
//                setcookie("p3dbuserpsw",$userpsw,time()+(60*60*24*365));
//                //echo $_COOKIE['p3dbuserid'].$_COOKIE['p3dbuserpsw'];
//	} else {
//                $userid = $_COOKIE['p3dbuserid'];
//                $userpsw = $_COOKIE['p3dbuserpsw'];
//        }

        include './template.php';
        //$error = !verifyid(".",$userid,$userpsw);
        $error = false;
        
//        if (!$error){
//                $query = "INSERT INTO user_visit(userid,ip,date,time) VALUES ('$userid','{$_SERVER['REMOTE_ADDR']}',NOW(),NOW());";
//                if (mysql_query($query)){
//                }
//        }

include 'dbconfig/config.php';
include 'dbconfig/opendb.php';
getHeader(".");
getTopBody(".");
?>


<?php
        if ($error) {
?>

        &nbsp;<br />
        <table width="100%" class="legend">

            <tr><td colspan="2"><b>Access to P<sup>3</sup>DB is restricted since the data has not been published.
                    It will be publicly available once published. If you need early access to the data,
                    please contact <a href="mailto:thelenj@missouri.edu">Jay Thelen</a>.
                    Thanks!</b>
            </td></tr>
            <tr><td>&nbsp;</td></tr>
            <form action="./index.php" method="post">
		<tr><td width="100">Username:</td><td><input type="text" name="p3dbuserid" value="<?php $_POST['p3dbuserid'] ?>"/></td></tr>
		<tr><td width="100">Password:</td><td> <input type="password" name="p3dbuserpsw" /></td></tr>
                <?php
                    if ($_POST['login']) {
                ?>
                <tr><td colspan="2"><font color="red"> Wrong username or password!</font></td></tr>
                <?php
                    }
                ?>
		<tr><td></td><td><input name="login" type="submit" id="login" value="login"></td></tr>
	    </form>
	</table>
<?php
        }

        $query = "SELECT version FROM p3dbInfo";
        $result = mysql_query($query) or die('Error, query failed'.$query);
        $row = mysql_fetch_array($result, MYSQL_ASSOC);
        $version = $row['version'];

        $query ="SELECT label,latin FROM organism ORDER BY latin;";
        $result = mysql_query($query) or die("Error, query failed: $query");
	while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            $orgs[$row['label']] = $row['latin'];
        }

        $query ="SELECT COUNT(*) AS count FROM dataSource ORDER BY pubmed DESC;";
        $result = mysql_query($query) or die("Error, query failed: $query");
	while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            $numref = $row['count'];
        }

        $query = "SELECT COUNT(*) as count,organism FROM protein ".
                 "GROUP BY organism;";
        $result = mysql_query($query) or die("Error, query failed: $query");
	while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            $procountorg[$row['organism']] = number_format($row['count']);
        }

        $query = "SELECT COUNT(*) as count FROM protein;";
        $result = mysql_query($query) or die("Error, query failed: $query");
	while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            $procount = number_format($row['count']);
        }

        $query = "SELECT COUNT(*) as count,organism FROM site,protein ".
                 "WHERE site.protein=protein.id AND site.ptm='p' ".
                 "GROUP BY organism;";
        $result = mysql_query($query) or die("Error, query failed: $query");
	while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            $sitecountorg[$row['organism']] = number_format($row['count']);
        }

        $query = "SELECT COUNT(*) as count FROM site WHERE site.ptm='p';";
        $result = mysql_query($query) or die("Error, query failed: $query");
	while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            $sitecount = number_format($row['count']);
        }
?>

    <p class="pageName">WELCOME TO P<sup>3</sup>DB!</p>

    <p> P<sup>3</sup>DB version <?php echo $version; ?> hosts protein phosphorylation data for
        <?php echo count($orgs); ?> species from <?php echo $numref; ?> experimental studies,
        containing <a href="data/protein_list.php"><?php echo $procount; ?></a> phosphoproteins,
        harboring <?php echo $sitecount; ?> phosphosites.
    </p>
        <table border="1" cellpadding="2">
        <tr><td>Organism</td><td align="center">Phosphoproteins</td><td align="center">Phosphosites</td></tr>

        <?php
        foreach ($orgs as $orgid=>$latin) {
            echo "<tr><td><i>$latin</i></td>";
            echo "<td align=\"center\"><a href=\"data/protein_list.php?org=$orgid\">{$procountorg[$orgid]}</a></td>";
            echo "<td align=\"center\">".$sitecountorg[$orgid]."</td>";
            echo "</td></tr>";
        }
        ?>
        </table>
        <a href="statistics.php">More statistics</a>

    <table border="0" cellspacing="0" cellpadding="0" >
            <tr> <td> &nbsp; </td> </tr>
            <tr> <td> <hr /> </td> </tr>
            <tr> <td> &nbsp; <td> </tr>

            <tr> <td>
                    <u><b>Mailing list</b></u><br/>
                  <ul>
                  <li>
                    Subscribe to the low-traffic
                    <a href="http://groups.google.com/group/p3db-announce" target="_blank" title="Musite Announcement">Announcement mailing list</a> to keep updated on P<sup>3</sup>DB, such as its future releases: <br/>
                  
                    <form action="http://groups.google.com/group/p3db-announce/boxsubscribe">
                      <font size="-1">&nbsp;&nbsp;Email:</font>
                      <input type=text name=email>
                      <input type=submit name="sub" value="Subscribe">
                    </form>
                  </li>
                  </ul>
            </td></tr>

            <tr> <td> &nbsp; </td> </tr>
            <tr> <td> <hr /> </td> </tr>
            <tr> <td> &nbsp; <td> </tr>

            <tr> <td>
                  <u><b> Cite P<sup>3</sup>DB </b></u><br/>
                  <ul>
                  <li>
                    Jianjiong Gao, Ganesh Kumar Agrawal, Jay J. Thelen and Dong Xu.
                    P<sup>3</sup>DB: a plant protein phosphorylation database.
                    <i>Nucleic Acids Res</i> 2009.
                    37(Database issue):D960-2.
                    &nbsp;&nbsp;<a href="http://www.ncbi.nlm.nih.gov/pubmed/18931372" target="_blank">PubMed</a>
                    &nbsp;&nbsp;<a href="http://nar.oxfordjournals.org/cgi/content/full/gkn733" target="_blank">NAR</a>
                  </li>
                  </ul>
            </td></tr>

            <tr> <td> &nbsp; </td> </tr>
            <tr> <td> <hr /> </td> </tr>
            <tr> <td> &nbsp; </td> </tr>

            <tr> <td>
                    <p> This project is supported by <a href="http://www.nsf.gov">National Science Foundation</a> (award ID: DBI-0604439). </p>
            </td> </tr>

    </table>

<?php
	include 'dbconfig/closedb.php';
        getBottom(); ?>
